/**
 * 
 */
package org.sensmon.core.datamodel;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.nio.DoubleBuffer;
import java.nio.IntBuffer;

import org.extdev.connection.Connection;
import org.extdev.device.ltr.LTR11LibDevice;
import org.extdev.libraries.ltr.LTR11APILibraryFacade;
import org.extdev.libraries.ltr.LTRData;
import org.extdev.libraries.ltr.LTRException;
import org.extdev.protocol.Protocol;
import org.extdev.protocol.ltr.LTR11LibProtocol;

/**
 * @author LAP
 *
 */
public class LTR11Device extends LTR11LibDevice {

	public LTR11Device(LTR11APILibraryFacade facade) throws LTRException, SecurityException, IOException {
		super(new LTR11Connection(facade), new LTR11LibProtocol(facade), facade);
	}
	
	@SuppressWarnings("unchecked")
	public DoubleBuffer getData() {
		DoubleBuffer buffer = null;
		try {
			buffer = (DoubleBuffer) ((Protocol<IntBuffer, DoubleBuffer>)getProtocol()).rewriteData(((LTRData) ((ObjectInputStream) getConnection().getInputStream()).readObject()).getData());
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return buffer;
	}
	
	public LTR11APILibraryFacade getFacade() {
		return facade;
	}
}
